/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: workflow_test.hpp
 */

#ifndef _SYNLOGGER_TEST_HPP
#define _SYNLOGGER_TEST_HPP

#include "synlogger.hpp"
#include <boost/thread.hpp>
#include <boost/bind.hpp>

using namespace std;

namespace middleware {
//-----------------------------------------------------------------------------
// Definitions
void LogTest();
void LogTestMultiThread();
void ThreadLogger(int n);
SynLogger log("log_test","LOG_TEST");
//-----------------------------------------------------------------------------
// Implementations
void LogTest() {
	SynLogger log("log_test","LOG_TEST");
	log.Print("This is a single thread test");
}
void LogTestMultiThread() {
	boost::thread myThread1(boost::bind(&ThreadLogger, 1));
	boost::thread myThread2(boost::bind(&ThreadLogger, 2));
	boost::thread myThread3(boost::bind(&ThreadLogger, 3));
	myThread1.join();
	myThread2.join();
	myThread3.join();
}
void ThreadLogger(int n) {
	ostringstream s;
	s << "This is a multithread test. " << n;
	for(;;) {
		log.Print(s.str());
		boost::this_thread::sleep(boost::posix_time::milliseconds(3000));
	}
}
} /* middleware */

#endif
